package com.avic.modules.realtime.entity;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.TimeZone;

public class OpcWsIPA {

    /**
     * this sot of timestamp is ISO8601 time format
     *{ "code":"TEMPERATURE_01_01","tag":"channel_67190a.device_01.TEMPERATURE_01_01","value":10.333333333333334,"sourceTime":"2022-06-14T22:22:37.919+08:00","serverTime":"2022-06-14T22:22:37.919+08:00"}
      */


    private String IPAName;

    private String value;

    private Long isoTime;

    public Long getIsoTime() {
        return isoTime;
    }

    public void setIsoTime(Long isoTime) {
        this.isoTime = isoTime;
    }

    public String getIPAName() {
        return IPAName;
    }

    public void setIPAName(String IPAName) {
        this.IPAName = IPAName;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public void setIsoTime(String isoTimeStr){
        try {
            this.isoTime = getTime(isoTimeStr);
        } catch (ParseException e) {
            this.isoTime = null;
            e.printStackTrace();
        }
    }

    public static Long getTime(String iso8601Time) throws ParseException {
        SimpleDateFormat dateParser = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
        dateParser.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
        return dateParser.parse(iso8601Time).getTime();
    }

    public static void main(String[] args) throws ParseException {
        SimpleDateFormat dateParser = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
        dateParser.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
        System.out.println(dateParser.parse("2022-06-14T22:22:37.919+08:00").getTime());
    }

}
